package com.app.controller 
{
	import org.puremvc.as3.interfaces.ICommand;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	import org.puremvc.as3.interfaces.INotification;
	
	import com.app.view.AppMediator;
	
	import com.app.model.HttpProxy; 
	import com.app.model.GameConfigProxy;
	
	import com.peachcastle.debug.Log;
	import com.peachcastle.debug.LogArray;
	
	/**
	 * ...
	 * @author kevin
	 */
	public class HttpCommand extends SimpleCommand implements ICommand
	{
		
		override public function execute(notification:INotification):void
		{
			var name:String = notification.getName();
			var params:* = notification.getBody();

			switch(name)
			{
				case AppMediator.FEEDBACK_SEND_INFO_REQUEST:
					feedbackInfoSend(params[0]);
					
					break;
					
				case AppMediator.FEEDBACK_SEND_AFFIX_REQUEST:
					feedbackAffixSend(params[0]);
					
					break;
			}
		}
		
		private function feedbackInfoSend(obj:Object):void
		{
			obj["mid"] = gameConfigP.self.mid;
			obj["s"] = gameConfigP.mtkey;
			
			httpP.sendData(HttpProxy.FEEDBACK_SEND_INFO, obj);
		}
		
		private function feedbackAffixSend(obj:Object):void
		{
			obj["mid"] = gameConfigP.self.mid;
			obj["s"] = gameConfigP.mtkey;
			obj["log"] = LogArray.read();
			
			httpP.sendData(HttpProxy.FEEDBACK_SEND_AFFIX, obj);
			
			LogArray.clear();
		}
		
		///////////////////////////////////////
		///// model 引用
		//////////////////////////////////////
		private function get httpP():HttpProxy
		{
			return facade.retrieveProxy(HttpProxy.NAME) as HttpProxy;
		}
		
		private function get gameConfigP():GameConfigProxy
		{
			return facade.retrieveProxy(GameConfigProxy.NAME) as GameConfigProxy;
		}
	}

}